/**
 * PullExActivity.java
 * com.jamin.pullrefresh
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2012-5-8 		wangjieming
 *
 * Copyright (c) 2012, TNT All Rights Reserved.
*/

package com.jamin.pullrefresh;

import com.jamin.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * ClassName:PullExActivity
 *
 * @author   wangjieming
 * @version  1.0
 * @since    v1.0
 * @Date	 2012-5-8 下午4:54:55 
 */
public class PullExActivity extends Activity{

	PullExListView listview = null;
	ExAdapter adapter = null;
	int i = 3;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pull_ex_activity);
		listview = (PullExListView) findViewById(R.id.pull_ex_list_view);
		adapter = new ExAdapter(this);
		listview.setAdapter(adapter);
		listview.setonRefreshListener(new PullExListView.OnRefreshListener() {
			@Override
			public void onRefresh() {
				new Thread(new Runnable() {  
					public void run() {  

						try {  
							Thread.sleep(1000);  
							i++;
						} catch (Exception e) {  
						}  
						runOnUiThread(new Runnable() {  
							public void run() {  
								adapter.notifyDataSetChanged();
								listview.onRefreshComplete(); 	
							}  
						});  
					}  
				}).start();  
			}
		});
		listview.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
			
			@Override
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				Toast.makeText(PullExActivity.this, "click group = " + groupPosition +", child = " + childPosition, Toast.LENGTH_SHORT).show();
				// TODO Auto-generated method stub
				return true;
				
			}
		});
		
		
		
		
	}

	
	class ExAdapter extends BaseExpandableListAdapter{

		Context ctx = null;
		public ExAdapter(Context ctx){
			this.ctx = ctx;
		}
		
		
		@Override
		public Object getChild(int groupPosition, int childPosition) {
			
			// TODO Auto-generated method stub
			return null;
			
		}

		@Override
		public long getChildId(int groupPosition, int childPosition) {
			
			// TODO Auto-generated method stub
			return 0;
			
		}

		@Override
		public View getChildView(int groupPosition, int childPosition,
				boolean isLastChild, View convertView, ViewGroup parent) {
			TextView tv = new TextView(ctx);
			tv.setHeight(40);
			tv.setText("hello child");
			return tv;
			
		}

		@Override
		public int getChildrenCount(int groupPosition) {
			
			// TODO Auto-generated method stub
			return 3;
			
		}

		@Override
		public Object getGroup(int groupPosition) {
			
			// TODO Auto-generated method stub
			return null;
			
		}

		@Override
		public int getGroupCount() {
			
			// TODO Auto-generated method stub
			return i;
			
		}

		@Override
		public long getGroupId(int groupPosition) {
			
			// TODO Auto-generated method stub
			return 0;
			
		}

		@Override
		public View getGroupView(int groupPosition, boolean isExpanded,
				View convertView, ViewGroup parent) {
			TextView tv = new TextView(ctx);
			tv.setHeight(70);
			tv.setText("hello group");
			// TODO Auto-generated method stub
			return tv;
			
		}

		@Override
		public boolean hasStableIds() {
			
			// TODO Auto-generated method stub
			return false;
			
		}

		@Override
		public boolean isChildSelectable(int groupPosition, int childPosition) {
			
			// TODO Auto-generated method stub
			return true;
			
		}
		
	}
	
	
	
}

